import React, { Component, Suspense } from 'react';
const Login = React.lazy(() => import('./login'));
const Register = React.lazy(() => import('./register'));
const Forget = React.lazy(() => import('./forget'));
const HomeWrapper = React.lazy(() => import('./home-wrapper'));
import Loading from '@/components/loading';
import './index.less';

export default class PagesLayout extends Component<any> {
  state = {
    isLogin: false,
  };

  render() {
    const { location } = this.props;
    let renderComponent;
    if (location.pathname === '/login' && !this.state.isLogin) {
      renderComponent = <Login />;
    } else if (location.pathname === '/register') {
      renderComponent = <Register />;
    } else if (location.pathname === '/forget') {
      renderComponent = <Forget />;
    } else {
      renderComponent = <HomeWrapper {...this.props}></HomeWrapper>;
    }
    return <Suspense fallback={<Loading />}>{renderComponent} </Suspense>;
  }
}
